package com.study.thread.poll;

import java.util.concurrent.FutureTask;

/**
 * @author mjy
 * @date 2021/12/01
 * @description
 */
public class CallableTest {


    public static void main(String[] args) throws Exception {

        ThreadPool threadPool = new ThreadPool();
        FutureTask<Integer> future = new FutureTask<>(threadPool);
        Thread thread = new Thread(future);
        thread.start();
        thread.sleep(100);
        //尝试取消对此任务的执行()
        future.cancel(true);
        //判断是否在任务完成前取消
        System.out.println("任务取消成功:"+future.isCancelled());
        if (!future.isCancelled()){
            System.out.println("任务取消失败");
        }
        //判断任务是否已经完成
        System.out.println("任务是否完成："+future.isDone());
        if (!future.isDone()){
            System.out.println("future get="+future.get());
        }else {//任务已完成
            System.out.println("task is done");
        }
    }




}
